
/**
 * A 2-by-2 matrix. Stored in column-major order.
 * This is really just a wrapper class for b2Mat22 in C++. You
 * should not use methods in this class too often, because this
 * will potentially decrease performance. This class is provided
 * mainly for consistency.
 * */
public class b2Mat22 extends b2AllocationGuard{

	/** The default constructor does nothing. */
	public b2Mat22() {
		address = jni_b2Mat22();
	}

	/** Construct this matrix using columns.*/
	public b2Mat22(final b2Vec2 c1, final b2Vec2 c2) {
		address = jni_b2Mat22_vec(c1.address, c2.address);
	}

	/** Construct this matrix using scalars. */
	public b2Mat22(float a11, float a12, float a21, float a22) {
		address = jni_b2Mat22_float(a11, a12, a21, a22);
	}

	/** Initialize this matrix using columns. */
	public void Set(final b2Vec2 c1, final b2Vec2 c2) {
		jni_b2Mat22_Set(address, c1.address, c2.address);
	}

	/** Set this to the identity matrix. */
	public void SetIdentity() {
		jni_b2Mat22_SetIdentity(address);
	}

	/** Set this matrix to all zeros. */
	public void SetZero() {
		jni_b2Mat22_SetZero(address);
	}

	public b2Mat22 GetInverse() {
		int add = jni_b2Mat22_GetInverse(address);
		return new b2Mat22(add);
	}

	public b2Vec2 Solve(final b2Vec2 b) {
		int addr = jni_b2Mat22_Solve(address, b.address);
		b2Vec2 obj = new b2Vec2(addr);
		return obj;
	}

	@Override
	public void release() {
		if ( address != 0 ) {
			jni_b2Mat22_release(address);
		}
		super.release();
	}


	private static native int jni_b2Mat22();
	private static native int jni_b2Mat22_vec(int c1, int c2);
	private static native int jni_b2Mat22_float(float a11, float a12, float a21, float a22);

	private static native void jni_b2Mat22_Set(int me, int c1, int c2);
	private static native void jni_b2Mat22_SetIdentity(int me);
	private static native void jni_b2Mat22_SetZero(int me);
	private static native int jni_b2Mat22_GetInverse(int me);
	private static native int jni_b2Mat22_Solve(int me, int b);
	private static native void jni_b2Mat22_release(int me);
}
